package com.shigui.news.interceptor;




import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.shigui.news.controller.BaseAction;
import com.shigui.news.enums.ResponseCode;
import com.shigui.news.enums.UserType;
import com.shigui.news.exception.UserException;
import com.shigui.news.model.User;

public class Permission extends MethodFilterInterceptor{

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		// TODO Auto-generated method stub
		BaseAction action = (BaseAction) invocation.getAction();
		User loginUser = action.findByPersistCodeOrFail();
		
		if(loginUser.getType().equals(UserType.MANAGER.getCode())){
			
			return invocation.invoke();
		
		}else{
			throw new UserException(ResponseCode.USER_INVALID_OPERATION);
		}
	}

}
